using System;

namespace Think.Problems.Solitaire
{
    public class SolitaireRule : IRule
    {
        /// <summary>
        /// Whether the given travelling card (<paramref name="a_base"/>) can be set upon the given base card 
        ///     (<paramref name="a_travelling"/>).
        /// </summary>
        /// <param name="a_base">Base card.</param>
        /// <param name="a_travelling">Travelling card.</param>
        /// <returns>true if travelling tablea can be set.</returns>
        /// <exception cref="ArgumentNullException">Thrown if "<paramref name="a_base"/>" is null.</exception>
        /// <exception cref="ArgumentNullException">Thrown if "<paramref name="a_travelling"/>" is null.</exception>
        public bool CanSet(string a_base, string a_travelling)
        {
            if (Card.Color(a_base) == Card.Color(a_travelling))
                return false;

            if (Card.RankValue(a_base) != Card.RankValue(a_travelling) + 1)
                return false;

            return true;
        }

        /// <summary>
        /// Whether the given travelling card (<paramref name="a_travelling"/>) can be set on an empty tableau.
        /// </summary>
        /// <param name="a_travelling">Travelling card.</param>
        /// <returns>True if travelling card can be set.</returns>
        /// <exception cref="ArgumentNullException">Thrown if "<paramref name="a_travelling"/>" is null.</exception>
        public bool CanSetOnEmpty(string a_travelling)
        {
            #region Argument Validation

            if (a_travelling == null)
                throw new ArgumentNullException("a_travelling");

            #endregion

            return Card.RankValue(a_travelling) == 13; // King
        }
    }
}